<?php
/*
RewriteRule ^latex/([a-z]*)_([0-9]*)\.png$ visu.php?type=png&path=$1&uid=$2 [L]
RewriteRule ^latex/fiche_([0-9]*)\.tex$ visu.php?type=tex&uid=$1 [L]
RewriteRule ^latex/fiche_corrigee_([0-9]*)\.pdf$ visu.php?type=pdfcorrige&uid=$1 [L]
RewriteRule ^latex/fiche_([0-9]*)\.pdf$ visu.php?type=pdf&uid=$1 [L]
*/

// TODO : Mettre des droits

$_GET["uid"] = str_replace(array("\"", "'", ".", "\\", "/","<", ">", "=", "?", "&"), "", $_GET["uid"]);
$_GET["path"] = str_replace(array("\"", "'", ".", "\\", "/","<", ">", "=", "?", "&"), "", $_GET["path"]);
$_GET["type"] = str_replace(array("\"", "'", ".", "\\", "/","<", ">", "=", "?", "&"), "", $_GET["type"]);

switch($_GET["type"]){

	case "png":

		// Images PNG
		header("Content-type: image/png");
		echo implode("", file("./staticdata/latex/".$_GET["path"]."/".$_GET["uid"].".png"));

	break;

	case "tex":

		// Fichier TeX de la fiche exo
		header("Content-type: text/plain");
		header('Content-Disposition: attachment; filename="fiche_'.$_GET["uid"].'.tex"');
		echo implode("", file("./staticdata/latex/fiche/".$_GET["uid"].".tex"));

	break;

	case "pdf":

		// Version PDF sans solution
		// TODO

	break;

	case "pdfcorrige":

		// Version PDF avec correction
		// TODO

	break;

}

?>
